package com.xingfudazi.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingfudazi.app.domain.AppFollowRel;
import com.xingfudazi.app.domain.ImFriend;
import com.xingfudazi.app.mapper.ImFriendMapper;
import com.xingfudazi.app.service.IAppMemberInfoService;
import com.xingfudazi.app.service.ImFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author YuJiaMing
 * date 2024年07月27日 13:29
 */
@Service
public class ImFriendServiceImpl extends ServiceImpl<ImFriendMapper, ImFriend> implements ImFriendService {

    @Autowired
    private IAppMemberInfoService appMemberInfoService;

    @Override
    public void addByAppFollowRel(AppFollowRel appFollowRel) {
        ImFriend imFriend = new ImFriend();
        imFriend.setId(appFollowRel.getId());
        imFriend.setUserId(appFollowRel.getNid());
        imFriend.setFriendId(appFollowRel.getFollowId());

        String nickName = appMemberInfoService.selectAppMemberInfoById(appFollowRel.getFollowId()).getNickName();
        imFriend.setFriendNickName(nickName);
        imFriend.setCreatedTime(new Date());

        this.save(imFriend);
    }

    @Override
    public void delByAppFollowRel(Long followId, Long userId) {
        LambdaQueryWrapper<ImFriend> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ImFriend::getFriendId, followId);
        wrapper.eq(ImFriend::getUserId, userId);
        this.remove(wrapper);
    }
}
